<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
%>
<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.text.*"%>
<%@ include file="Connections/conDB.jsp" %>
<% int validaSession = 2; %>
<%@ include file="Connections/session.jsp" %>

<%
String rsId_pedim = "";
String rsAnio = "";
String rsAduana = "";
String rsNumero = "";
String rsFecha = "";
String rsCantidad_desc = "";
String rsNo_patente = "";
String rsFirma_elect = "";
String rsArancel = "";
String rsObservaciones = "";
String parId_comp = request.getParameter("id_comp");

NumberFormat nf  = new DecimalFormat("#,###.###");
nf.setMinimumFractionDigits(3);

Driver DriverRs = (Driver)Class.forName(MM_conDB_DRIVER).newInstance();
Connection ConnRs = DriverManager.getConnection(MM_conDB_STRING,MM_conDB_USERNAME,MM_conDB_PASSWORD);
String query = "SELECT "+
				"id_pedim, anio, numero, aduana, CONVERT(VARCHAR,fecha,103) AS fecha, "+
				"cantidad_desc, no_patente, arancel, observaciones "+
				"FROM pedimento "+
				"WHERE compra IS NULL "+
				"ORDER BY fecha DESC";
//out.print(query);
PreparedStatement StatementRs = ConnRs.prepareStatement(query);
ResultSet Rsquery = StatementRs.executeQuery();
boolean Rsquery_hasData = Rsquery.next();

%>

<html>
<head>
<title>CIMA v2 - Compras Asociar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="miestilo.css" type="text/css">
<script>
// --------
	function checkValor(obj) {
		if (obj.checked) {
			document.form1.pedimValor.value = (document.form1.pedimValor.value*1)+1;
		} else {
			document.form1.pedimValor.value = (document.form1.pedimValor.value*1)-1;
		}
	}
//--------
	function asociar() {
		if (valida()) {
			document.form1.submit();
		}
	}
//--------
function valida () {
	var Doc = document.form1;
	missinginfo = "";
	if ((Doc.pedimValor.value*1) <= 0)     missinginfo += "\n     - Seleccione un Pedimento";

	if (missinginfo != "") {
		missinginfo = "_________________________\n" + missinginfo +
					  "\n_________________________\n";
		alert(missinginfo);
		return false;
	}else{
		Doc.modalidad.value = "asociar";
		return true;
	}

}
//-----------
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" background="images/fondo.jpg">
<center>
<br>
  <form name="form1" action="compras_asocQuery.jsp" method="post">
    <table width="350" border="0" cellpadding="0" cellspacing="0">
      <tr> 
        <td class="titulos" align="center" colspan="8">Pedimentos</td>
      </tr>
      <tr> 
        <td class="titcolumna">&nbsp;<input type="hidden" name="pedimValor" value="0"></td>
        <td class="titcolumna">&nbsp;</td>
        <td class="titcolumna" align="center">A&ntilde;o</td>
        <td class="titcolumna" align="center">Aduana</td>
        <td class="titcolumna" align="center">N&uacute;mero</td>
        <td class="titcolumna" align="center">Fecha</td>
        <td class="titcolumna" align="center">Cantidad</td>
        <!--<td class="titcolumna" align="center">Firma</td>-->
      </tr>
	<%  int num = 0;
		while (Rsquery_hasData) {
		  num++;
			rsId_pedim = Rsquery.getString("id_pedim");
			rsAnio = Rsquery.getString("anio");
			rsAduana = Rsquery.getString("aduana");
			rsNumero = Rsquery.getString("numero");
			rsFecha = Rsquery.getString("fecha");
			rsCantidad_desc = nf.format(Rsquery.getObject("cantidad_desc"));
			rsNo_patente = Rsquery.getString("no_patente");
			//rsFirma_elect = Rsquery.getString("firma_elect");
			rsArancel = Rsquery.getString("arancel");
			rsObservaciones = Rsquery.getString("observaciones");
	%>
      <tr> 
        <td class="textcolumna" align="center"><%=num%></td>
        <td align="center" class="textcolumna"> 
          <input type="checkbox" name="cbId_pedimento" value="<%=rsId_pedim%>" class="textfields" onClick="checkValor(this)">
        </td>
        <td class="textcolumna" align="center"><%=rsAnio%></td>
        <td class="textcolumna" align="center"><%=rsAduana%></td>
        <td class="textcolumna" align="center"><%=rsNumero%></td>
        <td class="textcolumna" align="center"><%=rsFecha%></td>
        <td class="textcolumna" align="right"><%=rsCantidad_desc%> ton.</td>
        <!--<td class="textcolumna" align="center"><% //rsFirma_elect%></td>-->
      </tr>
	<%
	  Rsquery_hasData = Rsquery.next();
	}
	%>
    </table>
<br>
    <table width="350" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="right"> 
          <input type="hidden" name="modalidad" value="asociar">
          <input type="hidden" name="id_comp" value="<%=parId_comp%>">
		<a href="javascript:asociar()"><img src="images/bAsociar.gif" width="82" height="18" border="0"></a>&nbsp; 
          <a href="javascript:window.close()"><img src="images/bCerrar.gif" width="82" height="18" border="0"></a></td>
  </tr>
</table>
</form>
</center>
</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
<%
Rsquery.close();
StatementRs.close();
ConnRs.close();
%>